// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// Copyright (c) Microsoft Corporation. All rights reserved

#include "Private.h"
#include "EditSession.h"
#include "GetTextExtentEditSession.h"
#include "TfTextLayoutSink.h"

//+---------------------------------------------------------------------------
//
// ctor
//
//----------------------------------------------------------------------------

CGetTextExtentEditSession::CGetTextExtentEditSession(_In_ CSampleIME* pTextService, _In_ ITfContext* pContext, _In_ ITfContextView* pContextView, _In_ ITfRange* pRangeComposition, _In_ CTfTextLayoutSink* pTfTextLayoutSink) : CEditSessionBase(pTextService, pContext) {
	_pContextView = pContextView;
	_pRangeComposition = pRangeComposition;
	_pTfTextLayoutSink = pTfTextLayoutSink;
}

//+---------------------------------------------------------------------------
//
// ITfEditSession::DoEditSession
//
//----------------------------------------------------------------------------

STDAPI CGetTextExtentEditSession::DoEditSession(TfEditCookie ec) {
	RECT rc = { 0, 0, 0, 0 };
	BOOL isClipped = TRUE;

	if (SUCCEEDED(_pContextView->GetTextExt(ec, _pRangeComposition, &rc, &isClipped))) {
		_pTfTextLayoutSink->_LayoutChangeNotification(&rc);
	}

	return S_OK;
}
